<template>
  <div class="main">
    <div class="top"></div>
    <div class="mid">
      <div class="word">登录</div>
      <el-form :model="form" style="width: 300px">
        <el-form-item>
          <el-input v-model="username" placeholder="请输入账号" />
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="password"
            type="password"
            placeholder="请输入密码"
            show-password
          />
        </el-form-item>
        <el-form-item class="center">
          <el-button type="primary" @click="doLogin" color="#DBEBE1"
            >登录</el-button
          >
          <el-button @click="this.$router.push({ path: 'register' })"
            >注册</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="bottom"></div>
  </div>
</template>

<script>
import { login, info } from "../api/patient";

export default {
  name: "",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    doLogin() {
      login({ username: this.username, password: this.password }).then(
        (res) => {
          this.$store.commit('setToken', res.data.authorization);
          this.doInfo()
          this.toHomePage();
          this.$store.commit("setTopBar", 0);
        }
      );
    },
    doInfo() {
      info({}).then(
        (res) => {
          this.$store.commit('setName', res.data.name);
        }
      );
    },

    toHomePage() {
      this.$router.push({
        path: "/",
      });
    },
  },
};
</script>

<style scoped>
.main {
  width: 100vw;
  height: 100vh;
  background: url(@/assets/10.jpg) no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed;
}

.top {
  width: 100%;
  height: 110px;
}

.word {
  text-align: center;
  font-size: 50px;
  color: rgb(255, 255, 255);
}

.center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mid {
  width: 350px;
  height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
  background-color: rgba(255, 255, 255, 0.5);
  border-radius: 40px 40px 40px 40px;
}

.bottom {
  width: 100%;
  height: 240px;
}
</style>